using UnityEngine;
using UnityEngine.UI;
using System;
using TMPro;
using Launcher;

namespace Launcher
{
    /// <summary>
    /// UI加载阶段提示。
    /// </summary>
    public class UIForceUpdate : UIBase
    {
        public TextMeshProUGUI _label_message;
        public TextMeshProUGUI _label_size;
        public TextMeshProUGUI _label_net_info;

        public Button _btn_ok;
        public Button _btn_cancel;

        public Action OnOk;
        public Action OnCancel;

        void Start()
        {
            _btn_ok.onClick.AddListener(OnBtnOK);
            _btn_cancel.onClick.AddListener(OnBtnCancel);
        }

        public override void OnEnter(object data)
        {
            //#region 强更弹框

            //public string Label_ForceUpdate_Message = "发现重要版本更新，请立即更新。";
            //public string Label_ForceUpdate_Size = "资源大小：<color=blue>{0}</color>";
            //public string Label_ForceUpdate_NetInfo_Wifi = "已在WiFi环境下，请放心更新";
            //public string Label_ForceUpdate_NetInfo_No_Wifi = "建议在WiFi环境下下载";

            //public string Btn_ForceUpdate_Agree = "立即更新";
            //public string Btn_ForceUpdate_Refuse_Quit = "退出游戏";
            //public string Btn_ForceUpdate_Refuse_Ignore = "暂不更新";
            //#endregion

            _label_message.text = LoadText.Instance.Label_ForceUpdate_Message;


            _btn_ok.GetComponentInChildren<TextMeshProUGUI>().text = LoadText.Instance.Btn_ForceUpdate_Agree;
            bool canIgnore = (bool)data;
            _btn_cancel.GetComponentInChildren<TextMeshProUGUI>().text = canIgnore ? LoadText.Instance.Btn_ForceUpdate_Refuse_Ignore : LoadText.Instance.Btn_ForceUpdate_Refuse_Quit;



            //_label_net_info.text = LoadText.Instance.Label_ForceUpdate_Message;












        }

        private void OnBtnOK()
        {
            if (OnOk == null)
            {
                Debug.LogWarning("UIForceUpdate无点击事件");
            }
            else
            {
                OnOk();
            }
            _OnClose();
        }

        private void OnBtnCancel()
        {
            if (OnCancel == null)
            {
                Debug.LogWarning("UIForceUpdate无点击事件");
            }
            else
            {
                OnCancel();
            }
        }

        private void _OnClose()
        {
            LauncherMgr.Hide(UIDefine.UIForceUpdate);
        }
    }
}